﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ProjectBordspil.Sevices;

namespace ProjectBordspil.Models
{
    public class AppRepository : IAppRepository
    {
        AppDataContext context = new AppDataContext();
        ///<summary>
        ///construct an empty list of GameModel objects
        ///</summary>
        List<GameModel> m_games = new List<GameModel>();

        ///<summary>
        ///Gets all registered user
        ///</summary>
        public IEnumerable<UserModel> GetAllPlayers
        {
            get { return context.UserModel; }
            set
            {
            }
        }

        ///<summary>
        ///Gets all games
        ///</summary>
        public IEnumerable<GameModel> GetAllGames
        {
            get { return context.GameModel; }
            set
            {
            }
        }

        ///<summary>
        ///Gets all memory images
        ///</summary>
        public List<MemImages> GetAllMemImages
        {
            get { return (context.MemImages).ToList(); }
            set
            {
            }
        }

        ///<summary>
        ///List of action image objects for the Guillontine game
        ///</summary>
        public List<GuiImageAction> GetAllActImages()
        {
            List<GuiImageAction> m_act_images = new List<GuiImageAction>();
            m_act_images = context.GuiImageAction.ToList();
            return m_act_images;
        }

        ///<summary>
        ///List of nobel image objects for the Guillontine game
        ///</summary>
        public List<GuiImageNobel> GetAllNobImages()
        {
            List<GuiImageNobel> m_nob_images = new List<GuiImageNobel>();
            m_nob_images = context.GuiImageNobel.ToList();
            return m_nob_images;
        }

        ///<summary>
        ///List of all active games
        ///</summary>
        public IEnumerable<ActiveGames> GetActiveGames
        {
            get { return context.ActiveGames; }
            set
            {
            }
        }

        ///<summary>
        ///Adds a new game to the list of new games
        /// </summary>
        public void AddNewGame(ActiveGames gg)
        {
            context.ActiveGames.Add(gg);

            SaveDataContextChanges();
        }

        ///<summary>
        ///Adds a new MemImageInfo object to table
        /// </summary>
        public void AddImageInfo(MemImageInfo gg)
        {
            context.MemImageInfo.Add(gg);

            SaveDataContextChanges();
        }

        ///<summary>
        ///Adds all MemImageInfo object to table
        /// </summary>
        public void AddAllMemImageInto(List<MemImageInfo> gg)
        {
            foreach( var item in gg)
            {
                context.MemImageInfo.Add(item);

                SaveDataContextChanges();
            }
        }
        ///<summary>
        ///Adds a new GuiNobImgInfo object to table
        /// </summary>
        public void AddAllNobImageInto(List<GuiNobImgInfo> gg)
        {
            foreach (var item in gg)
            {
                context.GuiNobImgInfo.Add(item);

                SaveDataContextChanges();
            }
        }

        ///<summary>
        ///Adds a new GuiActImgInfo object to table
        /// </summary>
        public void AddAllActImageInto(List<GuiActImgInfo> gg)
        {
            foreach (var item in gg)
            {
                context.GuiActImgInfo.Add(item);

                SaveDataContextChanges();
            }
        }

        ///<summary>
        ///Adds user info to table
        /// </summary>
        public void AddUserInfo(UserModel gg)
        {
            context.UserModel.Add(gg);

            SaveDataContextChanges();
        }

        /// <summary>
        /// Saves changes to datacontext
        /// </summary>
        public void SaveDataContextChanges()
        {
            context.SaveChanges();
        }

        ///<summary>
        ///Gets a list of nobel cards
        /// </summary>
        public List<GuiImageNobel> GetNobels()
        {
            List<GuiImageNobel> tempList = new List<GuiImageNobel>();

            tempList = context.GuiImageNobel.ToList();

            return tempList;
        }

        ///<summary>
        ///Gets a list of action cards
        /// </summary>
        public List<GuiImageAction> GetActions()
        {
            List<GuiImageAction> tempList = new List<GuiImageAction>();

            tempList = context.GuiImageAction.ToList();

            return tempList;
        }
    }
}